$(function () {
    var meetSel = $.Params.create();
    meetSel.ajax("get", getMeetIP() + "build", function (data) {
        html = "<option value='0'>请选择会议厅</option>";
        if(data.count > 0){
            $.each(data.rows,function(i,val){
                html+="<option value = '"+val.id+"'>"+val.buildTitle+"</option>";
            })
        }
       $("#buildTitle").html(html);
    })

    $("#buildTitle").on("change",function(){
        var buildId = $(this).val();
        getSubject(buildId);
    })

    function getSubject(buildId){
        var subjectSel = $.Params.create();
        subjectSel.addParams("buildId",buildId);
        subjectSel.ajax("get", getMeetIP() + "meetSubject", function (data) {
            var html = "<option value='0'>请选择专题</option>";
            if(data.count > 0){
                $.each(data.rows,function(i,val){
                    html+="<option value = '"+val.id+"'>"+val.subjectTitle+"("+val.meetDate+")</option>";
                })
            }
           $("#subjectTitle").html(html);
        })
    }
	var speakSel = $.Params.create();
	$("#searchBtn").on("click",function(){
		var name = $("#name").val();
		if(name != ""){
		speakSel.addParams("pTitle",name);
		}else{
		speakSel.addParams("pTitle",undefined);
		}
		speakData();
	})
	speakData();
	function speakData(){
		
		speakSel.ajax("get",getMeetIP() + "speakHost",function(data){
        var html = "<option value='0'>请选择讲者或主持</option>";
        if(data.count > 0){
            $.each(data.rows,function(i,val){
                html+="<option value = '"+val.id+"'>"+val.name+"</option>";
            })
        }
       $("#speakHost").html(html);
		})
	}
    

    $("#addData").on("click", function () {
        var buildId = $("#buildTitle").val();
        var meetSubjectId = $("#subjectTitle").val();
        var speakHostId = $("#speakHost").val();
        var name = $("#speakHost").find("option:selected").text();
        var scheduleTitle = $("#scheduleTitle").val();
        var startTime = $("#startTime").val();
        var endTime = $("#endTime").val();
        var meetTime = $("#meetTime").val();
        var meetDate = $("#meetDate").val();
        var type = $("#type").val();
        var addSel = $.Params.create();
        addSel.addParams("buildId", buildId);
        addSel.addParams("meetSubjectId", meetSubjectId);
        addSel.addParams("speakHostId", speakHostId);
        addSel.addParams("name", name);
        addSel.addParams("scheduleTitle", scheduleTitle);
        addSel.addParams("startTime", startTime);
        addSel.addParams("endTime", endTime);
        addSel.addParams("meetTime", meetTime);
        addSel.addParams("meetDate", meetDate);
        addSel.addParams("type", type);
        addSel.ajax("post", getMeetIP() + "meetSchedule", function (data) {
               window.location.href = "meetScheduleList.html";
        })
    })

    $("#cancelAdd").on("click", function () {
        history.go(-1);
    })
})